home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / BORLAND TURBO / CHESS.PAK / INFO.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  8.0 KB  |  271 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows - (C) Copyright 1991, 1993 by Borland International
  3. //----------------------------------------------------------------------------
  4. #include <owl/pch.h>
  5. #include <owl/static.h>
  6. #include <owl/gdiobjec.h>
  7. #include <owl/dc.h>
  8. #include <string.h>
  9. #include "wcdefs.h"
  10. #include "info.h"
  11. #include "externs.h"
  12.  
  13. short LEFTMARGIN = 6;
  14. short SEPERATOR = 4;
  15. #define MAXLINE    (INFOXSIZE - LEFTMARGIN -1)
  16.  
  17. #define COLORX     (LEFTMARGIN + CHARSIZE * 6)
  18. #define COLORY     (SEPERATOR + MYFRAMESIZE)
  19. #define COLORW     (CHARSIZE * 6)
  20. #define TIMERX    (LEFTMARGIN + CHARSIZE * 6)
  21. #define TIMERY    (COLORY + LINESIZE + SEPERATOR)
  22. #define TIMERW    (MAXLINE - TIMERX)
  23. #define WHITEINFOX    (LEFTMARGIN + CHARSIZE * 7)
  24. #define WHITEINFOY    (TIMERY + LINESIZE + SEPERATOR * 2)
  25. #define WHITEINFOW    (MAXLINE - WHITEINFOX)
  26. #define BLACKINFOX    (WHITEINFOX)
  27. #define BLACKINFOY   (WHITEINFOY + LINESIZE + SEPERATOR)
  28. #define BLACKINFOW   (WHITEINFOW)
  29. #define LEVELX   (LEFTMARGIN + CHARSIZE * 7)
  30. #define LEVELY   (BLACKINFOY + LINESIZE + SEPERATOR)
  31. #define LEVELW   (MAXLINE - LEVELX)
  32. #define VALUEX   (LEFTMARGIN + CHARSIZE * 7)
  33. #define VALUEY   (LEVELY + LINESIZE + SEPERATOR * 2)
  34. #define VALUEW   (MAXLINE - VALUEX)
  35. #define NODEX    (LEFTMARGIN + CHARSIZE * 8)
  36. #define NODEY    (VALUEY + LINESIZE + SEPERATOR)
  37. #define NODEW    (MAXLINE - NODEX)
  38. #define SECX    (LEFTMARGIN + CHARSIZE * 7)
  39. #define SECY    (NODEY + LINESIZE + SEPERATOR)
  40. #define SECW    (MAXLINE - SECX)
  41. #define DEPTHY   (SECY + LINESIZE + SEPERATOR)
  42. #define DEPTHX   (LEFTMARGIN + CHARSIZE * 7)
  43. #define DEPTHW   (MAXLINE - DEPTHX)
  44. #define STATBESTY (DEPTHY + LINESIZE + SEPERATOR * 2)
  45. #define BESTX    (LEFTMARGIN)
  46. #define BESTY    (STATBESTY + LINESIZE + 1)
  47. #define BESTW    (MAXLINE - LEFTMARGIN)
  48. #define BESTH    (LINESIZE * 3 + SEPERATOR * 3 - 9)
  49. #define MESSX    (LEFTMARGIN)
  50. #define MESSY    (BESTY + BESTH + SEPERATOR * 2)
  51. #define MESSW    (MAXLINE - MESSX)
  52.  
  53.  
  54. #define EmptyStr  ""
  55.  
  56.  
  57. //--------------- TNoEraseBkGndStatic methods -------------------
  58.  
  59. DEFINE_RESPONSE_TABLE1(TNoEraseBkGndStatic, TStatic)
  60.   EV_WM_ERASEBKGND,
  61. END_RESPONSE_TABLE;
  62.  
  63. TNoEraseBkGndStatic::TNoEraseBkGndStatic(TWindow* parent, int id, const char* title, int x,
  64.                     int y, int w, int h, WORD textLen)
  65.   : TStatic(parent, id, title, x, y, w, h, textLen)
  66. {
  67.   DoErase = TRUE;
  68.   LastLen = 0;
  69. }
  70.  
  71. BOOL
  72. TNoEraseBkGndStatic::EvEraseBkGnd(HDC hDC)
  73. {
  74.   if (DoErase) {
  75.     TDC dc(hDC);
  76.     dc.SelectStockObject(LTGRAY_BRUSH);
  77.     dc.PatBlt(GetClientRect(), PATCOPY);
  78.     DoErase = FALSE;
  79.     return TRUE;
  80.   }
  81.   return FALSE;
  82. }
  83.  
  84. void
  85. TNoEraseBkGndStatic::SetText(const char* text)
  86. {
  87.   int len = strlen(text);
  88.   if (len < LastLen)
  89.     SetErase();
  90.   TStatic::SetText(text);
  91.   LastLen = len;
  92. }
  93.  
  94. //---------------- TInfoWindow Methods -------------------------
  95.  
  96. DEFINE_RESPONSE_TABLE1(TInfoWindow, TWindow)
  97.   EV_WM_PAINT,
  98.   EV_WM_CTLCOLOR,
  99. END_RESPONSE_TABLE;
  100.  
  101. TInfoWindow::TInfoWindow(TWindow* parent, const char* title)
  102.   : TWindow(parent, title)
  103. {
  104.   Attr.Style |= WS_CHILD | WS_VISIBLE;
  105.   Attr.X = 3*BORDERSIZE + MAXBDSIZE*SQUARE_SIZE + 2*MYFRAMESIZE;
  106.   Attr.Y = BORDERSIZE;
  107.  
  108.   LEFTMARGIN= short(MYFRAMESIZE + CHARSIZE/2);
  109.   SEPERATOR = short(LINESIZE/4);
  110.   INFOXSIZE = short(28*CHARSIZE + 2*LEFTMARGIN);
  111.   INFOYSIZE = short(MESSY + LINESIZE + SEPERATOR + MYFRAMESIZE);
  112.   short temp = MAXBDSIZE * SQUARE_SIZE + 2*MYFRAMESIZE;
  113.   INFOYSIZE = (temp > INFOYSIZE) ? temp : INFOYSIZE;
  114.   InfoRect.right = Attr.W = INFOXSIZE;
  115.   InfoRect.bottom = Attr.H = INFOYSIZE;
  116.   InfoRect.left = InfoRect.top =  0;
  117.  
  118.   new TStatic(this, -1, " Turn:", LEFTMARGIN, COLORY, CHARSIZE*6, LINESIZE, 5);
  119.   new TStatic(this, -1, " White:", LEFTMARGIN, WHITEINFOY, CHARSIZE*7, LINESIZE, 4);
  120.   new TStatic(this, -1, " Black:", LEFTMARGIN, BLACKINFOY, CHARSIZE*7, LINESIZE, 6);
  121.   new TStatic(this, -1, " Time:", LEFTMARGIN, TIMERY, CHARSIZE*6, LINESIZE, 5);
  122.   new TStatic(this, -1, " Level:", LEFTMARGIN, LEVELY, CHARSIZE*13, LINESIZE, 12);
  123.   new TStatic(this, -1, " Value:", LEFTMARGIN, VALUEY, CHARSIZE*7, LINESIZE, 6);
  124.   new TStatic(this, -1, " Nodes:", LEFTMARGIN, NODEY, CHARSIZE*8, LINESIZE, 7);
  125.   new TStatic(this, -1, " N/Sec:", LEFTMARGIN, SECY, CHARSIZE*9, LINESIZE, 9);
  126.   new TStatic(this, -1, " Depth:", LEFTMARGIN, DEPTHY, CHARSIZE*7, LINESIZE, 6);
  127.   new TStatic(this, -1, " Bestline:", LEFTMARGIN-2, STATBESTY, MAXLINE-2, LINESIZE, 9);
  128.  
  129.   Color = new TStatic(this, -1, EmptyStr, COLORX, COLORY, COLORW, LINESIZE, 6);
  130.   WhiteInfo = new TStatic(this, -1, EmptyStr, WHITEINFOX, WHITEINFOY,
  131.     WHITEINFOW, LINESIZE, WHITEINFOW/CHARSIZE);
  132.   BlackInfo = new TStatic(this, -1, EmptyStr, BLACKINFOX, BLACKINFOY,
  133.     BLACKINFOW, LINESIZE, BLACKINFOW / CHARSIZE);
  134.   Timer = new TNoEraseBkGndStatic(this, -1, EmptyStr, TIMERX, TIMERY,
  135.     TIMERW, LINESIZE, WORD(TIMERW /CHARSIZE));
  136.   Level = new TStatic(this, -1, EmptyStr, LEVELX, LEVELY,
  137.     LEVELW, LINESIZE, LEVELW / CHARSIZE);
  138.   Value = new TStatic(this, -1, EmptyStr, VALUEX, VALUEY,
  139.     VALUEW, LINESIZE, VALUEW / CHARSIZE);
  140.   Nodes = new TStatic(this, -1, EmptyStr, NODEX, NODEY,
  141.     NODEW, LINESIZE, NODEW / CHARSIZE);
  142.   Seconds = new TStatic(this, -1, EmptyStr, SECX, SECY,
  143.     SECW, LINESIZE, SECW / CHARSIZE);
  144.   Depth = new TNoEraseBkGndStatic(this, -1, EmptyStr, DEPTHX, DEPTHY,
  145.     DEPTHW, LINESIZE, WORD(DEPTHW /CHARSIZE));
  146.   BestLine = new TStatic(this, -1, EmptyStr, BESTX, BESTY,
  147.     BESTW, BESTH, ((BESTW / CHARSIZE) * 3));
  148.   Message = new TStatic(this, -1, EmptyStr, MESSX, MESSY,
  149.     MESSW, LINESIZE, MESSW / CHARSIZE);
  150. }
  151.  
  152. void
  153. TInfoWindow::EvPaint()
  154. {
  155.   TPaintDC paintDC(HWindow);
  156.   DrawInfoFrame(paintDC);
  157.   DrawStaticFrames(paintDC);
  158. }
  159.  
  160. HBRUSH
  161. TInfoWindow::EvCtlColor(HDC hDC, HWND, UINT)
  162. {
  163.   SetBkColor(hDC, TColor(192, 192, 192));
  164.   return (HBRUSH)GetStockObject(LTGRAY_BRUSH);
  165. }
  166.  
  167. void
  168. TInfoWindow::Reset()
  169. {
  170.   Color->SetText("White");
  171.   WhiteInfo->Clear();
  172.   BlackInfo->Clear();
  173.   Level->Clear();
  174.   Value->Clear();
  175.   Nodes->Clear();
  176.   Seconds->Clear();
  177.   BestLine->Clear();
  178.   Message->Clear();
  179. }
  180.  
  181. void
  182. TInfoWindow::IterReset()
  183. {
  184.   Color->SetText("White");
  185.   Value->Clear();
  186.   Nodes->Clear();
  187.   Seconds->Clear();
  188.   BestLine->Clear();
  189. }
  190.  
  191. void
  192. TInfoWindow::DrawSFrame(TDC& dc, TRect& rect)
  193. {
  194.   dc.SelectStockObject(LTGRAY_BRUSH);
  195.   dc.PatBlt(rect);
  196.  
  197.   TPoint points[3];
  198.   TPen pen(TColor::LtGray);
  199.   dc.SelectObject(pen);
  200.   points[1].x = points[0].x = rect.left;
  201.   points[0].y = rect.bottom;
  202.   points[2].y = points[1].y = rect.top;
  203.   points[2].x = rect.right;
  204.   dc.Polyline(points, 3);
  205.  
  206.   dc.SelectStockObject(WHITE_PEN);
  207.   points[1].x = rect.right;
  208.   points[1].y = rect.bottom;
  209.   points[2].y = rect.top - 1;
  210.   dc.Polyline(points, 3);
  211. }
  212.  
  213. void
  214. TInfoWindow::DrawStaticFrames(TDC& dc)
  215. {
  216.   TRect rect;
  217.  
  218.   rect.left = LEFTMARGIN - 1;
  219.   rect.right = MAXLINE + 1;
  220.  
  221.   rect.top = COLORY - 1;
  222.   rect.bottom = COLORY + LINESIZE + 1;
  223.   DrawSFrame(dc, rect);
  224.  
  225.   rect.top = WHITEINFOY - 1;
  226.   rect.bottom = WHITEINFOY + LINESIZE + 1;
  227.   DrawSFrame(dc, rect);
  228.  
  229.   rect.top = BLACKINFOY - 1;
  230.   rect.bottom = BLACKINFOY + LINESIZE + 1;
  231.   DrawSFrame(dc, rect);
  232.  
  233.   rect.top = TIMERY - 1;
  234.   rect.bottom = TIMERY + LINESIZE + 1;
  235.   DrawSFrame(dc, rect);
  236.  
  237.   rect.top = LEVELY - 1;
  238.   rect.bottom = LEVELY + LINESIZE + 1;
  239.   DrawSFrame(dc, rect);
  240.  
  241.   rect.top = VALUEY - 1;
  242.   rect.bottom = VALUEY + LINESIZE + 1;
  243.   DrawSFrame(dc, rect);
  244.  
  245.   rect.top = NODEY - 1;
  246.   rect.bottom = NODEY + LINESIZE + 1;
  247.   DrawSFrame(dc, rect);
  248.  
  249.   rect.top = SECY - 1;
  250.   rect.bottom = SECY + LINESIZE + 1;
  251.   DrawSFrame(dc, rect);
  252.  
  253.   rect.top = DEPTHY - 1;
  254.   rect.bottom = DEPTHY + LINESIZE + 1;
  255.   DrawSFrame(dc, rect);
  256.  
  257.   rect.top = BESTY - 1;
  258.   rect.bottom = BESTY + BESTH + 1;
  259.   DrawSFrame(dc, rect);
  260.  
  261.   rect.top = MESSY - 1;
  262.   rect.bottom = MESSY + LINESIZE + 1;
  263.   DrawSFrame(dc, rect);
  264. }
  265.  
  266. void
  267. TInfoWindow::DrawInfoFrame(TDC& dc)
  268. {
  269.   DrawFrame(dc, InfoRect);
  270. }
  271.